//
//  ShowImageViewController.swift
//  WangPu
//
//  Created by xiaozhi on 15/11/2.
//  Copyright © 2015年 zhixiao. All rights reserved.
//

import UIKit

class ShowImageViewController: UIViewController {
    var scrollView:UIScrollView!
    var imageView:XZImageView!
    var imageurl:String?
    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "查看大图"
        let backItem = UIBarButtonItem(image: UIImage(named: "back_icon"), style:UIBarButtonItemStyle.Plain, target:self, action:"goBack")
        backItem.tintColor = UIColor.whiteColor()
        self.navigationItem.leftBarButtonItem = backItem
        self.automaticallyAdjustsScrollViewInsets = false
        self.view.backgroundColor = UIColor.blackColor()
        scrollView = UIScrollView(frame: CGRectMake(0, 64, view.bounds.size.width, view.bounds.size.height))
        scrollView.showsHorizontalScrollIndicator = false
        scrollView.showsVerticalScrollIndicator = false
        scrollView.delegate = self
        scrollView.backgroundColor = UIColor.clearColor()
        scrollView.minimumZoomScale = 0.5
        scrollView.maximumZoomScale = 2.0
        view.addSubview(scrollView)
        // Do any additional setup after loading the view.
        imageView = XZImageView(frame: scrollView.bounds)
        imageView.contentMode = UIViewContentMode.ScaleAspectFit
        scrollView.addSubview(imageView)
        if imageurl != nil{
            imageView.setImageWithUrl(imageurl!, defaultImage: nil)
        }
    }
    func  goBack(){
        self.navigationController?.popViewControllerAnimated(true)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
extension ShowImageViewController:UIScrollViewDelegate{
    func viewForZoomingInScrollView(scrollView: UIScrollView) -> UIView?{
        return self.imageView
    }
}
